import store from '@/store/index.js'
export default{
	common:{
		// baseUrl:"http://192.168.56.1:3000/api",
		baseUrl:"https://zyc618.mynatapp.cc/api",
		data:{},
		header:{
			"Content-Type":"application/json",
			"Content-Type":"application/x-www-form-urlencoded"
		},
		method:"GET",
		dataType:"json"
	},
	request(options={}){
		options.url=this.common.baseUrl+options.url;
		options.data = options.data || this.common.data;
		options.header = options.header || this.common.header;
		options.method = options.method || this.common.method;
		options.dataType = options.dataType || this.common.dataType
		
		if(options.header.token){
			options.header.token = store.state.user.token;
			if(! options.header.token){
				uni.showToast({
					title:"请先登录",
					icon:"none"
				})
				return uni.navigateTo({
					url:"/page/logn/logn"
				})
			}
		}
		
		return new Promise((res,rej)=>{
			uni.request({
				...options,// 深拷贝
				success: (result) => {
					if(result.statusCode !=200){
						return rej();
					}
					let data_content = result.data.data;
					res(data_content)
				}
			})
		})
	}
}